/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import cinemaEntidades.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hibernate.Transaction;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Administrador
 */
public class Dao {

  
    private final org.hibernate.classic.Session session;
//private Transaction tx;
  public Dao() {
           this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }


public void manejaExcepcion(HibernateException he) throws HibernateException
{
        try {
                    org.hibernate.Transaction tx = session.beginTransaction();

            tx.rollback();
        } catch (Exception ex) {}
       
    throw new HibernateException("Ocurrió un error en la capa de acceso a datos", he);
}  
   
    public List<Usuario> getUsuarios() {
       
        
        org.hibernate.Transaction tx = session.beginTransaction();
        Query q = session.createQuery ("from Usuario");
        List<Usuario> t = q.list();
        
        //List<Cancion> top =ordenadas.subList(0, 10);

        return t;
    }
       public List<Pelicula> getPeliculas() {
       
        
        org.hibernate.Transaction tx = session.beginTransaction();
        Query q = session.createQuery ("from Pelicula");
        List<Pelicula> t = q.list();
        
        //List<Cancion> top =ordenadas.subList(0, 10);

        return t;
    }
        public Pelicula consultaXId(int idPelicula) throws HibernateException
{ 
    Pelicula pelicula;  

    
          org.hibernate.Transaction tx = session.beginTransaction(); 
        pelicula=(Pelicula) session.get(Pelicula.class, idPelicula); 
    
    return pelicula; 
}
}
